package net.wangds.config.module;

import lombok.*;
import lombok.experimental.SuperBuilder;
import net.wangds.data.impl.IdCreate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
import java.util.ArrayList;
import java.util.List;

@Table(name="sys_config", indexes = {
        @Index(unique = true, columnList = "cata, item")
})
@Entity
@NoArgsConstructor(force = true)
@AllArgsConstructor
@Getter
@Setter
@SuperBuilder
public class Config extends IdCreate {

    private static final long serialVersionUID = 0;

    public static Config of(String cata, String item, String text, int version, String desc){
        Config res = new Config();
        res.setCata(cata);
        res.setItem(item);
        res.setText(text);
        res.setVersion(version);
        res.setDescription(desc);
        return res;
    }

    public static Config of(String cata, String item, String text, String parentItem, String parentText, int version, String desc){
        Config res = new Config();
        res.setCata(cata);
        res.setItem(item);
        res.setText(text);
        res.setVersion(version);
        res.setDescription(desc);
        res.setParentItem(parentItem);
        res.setParentText(parentText);
        return res;
    }

    /**
     * 分类.
     */
    @Column(length=64)
    private String cata;

    /**
     * key.
     */
    @Column(length=128)
    private String item;

    /**
     * 配置值.
     */
    @Column(columnDefinition = "TEXT")
    private String text;


    /**
     * 父项Key.
     */
    @Column(length=128)
    private String parentItem;

    /**
     * 父项配置值.
     */
    @Column(length=1000)
    private String parentText;

    @Column()
    private int version;

    @Column(length=2000)
    private String description;


}
